home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
PsL Monthly 1993 December
/
PSL Monthly Shareware CD-ROM (December 1993).iso
/
prgmming
/
dos
/
pascal
/
gsdbloo.exe
/
GS_STRNG.PAS
< prev
next >
Wrap
Pascal/Delphi Source File
|
1992-02-24
|
13KB
|
351 lines
unit GS_Strng;
{-----------------------------------------------------------------------------
String Handling Routines
GS_Strng Copyright (c) Richard F. Griffin
1 January 1991
102 Molded Stone Pl
Warner Robins, GA 31088
-------------------------------------------------------------
This unit handles the routines for string handling.
Changes:
13 Apr 91 - Added function Strip_Flip. This function will remove
trailing spaces and move any part of the string that
is preceeded by a '~' to the end of the string.
For Example:
Smith~John X.
will be converted to:
John X. Smith
on return.
This is ideal for maintaining a name alphabetically
while allowing a simple function to make the name
'normal' on display.
02 May 91 - Converted StrDate to accept a longint and convert to the
MM/DD/YY string format. The longint value is the julian
date (for example, 1 Jan 90 has a julian date of 2447893)
Added a ValDate function to convert a date string of
either MM/DD/YY or YYYYMMDD to the longint juilian day.
10 Aug 91 - Modified Unique_Field to return a unique field that can
also serve as a FileName. First character is alpha and
othere are alpha(uppercase) or numeric. Previously, the
routine returned uppercase, lowercase, and special chars.
------------------------------------------------------------------------------}
interface
{$D-}
uses
Crt,
Dos,
GS_Date;
function AllCaps(var t : string) : string;
procedure CnvAscToStr(var asc, st; lth : integer);
procedure CnvStrToAsc(var st, asc; lth : integer);
function Strip_Flip(st : string) : string;
function StrDate(jul : longint) : string;
function StrNumber(num : real; lth,dec : integer) : string;
function StrLogic(tf : boolean) : string;
function SubStr(s : string; b,l : integer) : string;
function TrimL(strn : string):string; {Deletes leading spaces}
function TrimR(strn : string):string; {Deletes trailing spaces}
function Unique_Field : string; {Used to create a unique 8-byte string}
function ValDate(strn : string) : longint;
function ValNumber(strn : string) : real;
function ValLogic(strn : string) : boolean;
implementation
function AllCaps(var t : string) : string;
var
i : integer;
s : string;
begin
s := t;
for i := 1 to length(s) do s[i] := upcase(s[i]);
AllCaps := s;
end;
procedure CnvAscToStr(var asc, st; lth : integer);
var
a : array[0..255] of byte absolute asc;
s : string[255] absolute st;
i : integer;
begin
move(a,s[1],lth);
s[0] := chr(lth);
i := pos(#0,s);
if i > 0 then dec(i)
else if a[0] <> 0 then i := lth;
s[0] := chr(i);
end;
procedure CnvStrToAsc(var st, asc; lth : integer);
var
a : array[0..255] of byte absolute asc;
s : string[255] absolute st;
t : string;
i : integer;
begin
t := s;
FillChar(a,lth,#0);
i := length(t);
if i >= lth then i := lth;
move(t[1],a,i);
end;
Function Strip_Flip(st : string) : string;
var
wst,
wstl : string;
i : integer;
begin
wst := TrimR(st);
wst := wst + ' ';
i := pos('~', wst);
if i <> 0 then
begin
wstl := substr(wst,1,pred(i));
system.delete(wst,1,i);
wst := wst + wstl;
end;
Strip_Flip := wst;
end;
function StrDate(jul : longint) : string;
begin
StrDate := GS_Date_View(jul);
end;
function StrNumber(num : real; lth,dec : integer) : string;
var
s : string;
begin
Str(num:lth:dec,s);
StrNumber := s;
end;
function StrLogic(tf : boolean) : string;
begin
if tf then StrLogic := 'T' else StrLogic := 'F';
end;
{.pa}
{
SUBSTR
╔══════════════════════════════════════════════════════════════════╗
║ ║
║ The SUBSTR function extracts a substring from a string. ║
║ ║
║ Calling the Method: ║
║ ║
║ x := SubStr(s,b,l) ║
║ ║
║ ( where x is the string to be trimmed. ║
║ s is of type string. ║
║ b is the integer start of substring. ║
║ l is the integer length of substring. ║
║ ║
║ ║
║ Result: ║
║ ║
║ A substring of l positions beginning at b is returned. ║
║ ║
╚══════════════════════════════════════════════════════════════════╝
}
Function SubStr(s : string; b,l : integer) : string;
var
st : string;
i : integer;
begin
st := '';
if b < 0 then b := 1;
st := copy(s, b, l);
SubStr := st;
end;
{.pa}
{
TRIML
╔══════════════════════════════════════════════════════════════════╗
║ ║
║ The TRIML function removes leading spaces from a field. ║
║ ║
║ Calling the Method: ║
║ ║
║ d := TrimL(x) ║
║ ║
║ ( where x is the string to be trimmed. ║
║ d is of type string. ║
║ ║
║ Result: ║
║ ║
║ Leading spaces are removed and the field returned. ║
║ ║
╚══════════════════════════════════════════════════════════════════╝
}
function TrimL(strn : string) : string;
var
st : string;
begin
st := strn; {Load work string}
while (length(st) > 0) and (st[1] = ' ') do delete(st, 1, 1);
{Loop to delete leading spaces}
TrimL := st; {Return trimmed string}
end;
{.pa}
{
TRIMR
╔══════════════════════════════════════════════════════════════════╗
║ ║
║ The TRIMR function removes trailing spaces from a field. ║
║ ║
║ Calling the Method: ║
║ ║
║ d := TrimR(x) ║
║ ║
║ ( where x is the string to be trimmed. ║
║ d is of type s